from odoo import models


class ProjectTask(models.Model):
    _name = 'project.task'
    _inherit = ["project.task", "directive.mixin"]

    def directive_on_done_post_message(self, payload: dict):
        for task in self:
            task.message_post(
                body=f"Директива выполнена: {payload.get('directive_name')})"
            )
        return True

    # def _directive_generation_spec(self):
    #     return [
    #         {
    #             "event": "on_callback",
    #             "callback": "action_demo_directive_callback",
    #             "mode": "create_once",
    #             "when": "after",
    #             "if_result": True,
    #             "use_record_template_group": True,
    #             "key": "demo_callback_v1",
    #         }
    #     ]

    def _directive_generation_spec(self):
        return [
            {
                "event": "on_write",
                "key": "stage_draft_to_progress",
                "field": "stage_id",
                "from": 9,
                "to": 10,
                "use_record_template_group": True,
                "mode": "create_once",
            }
        ]

    def action_demo_directive_callback(self):
        for task in self:
            task.message_post(body="Demo callback executed")
        return True