from odoo import models, fields


class AccountPayment(models.Model):
    _name = 'account.payment'
    _inherit = ["account.payment", "directive.mixin"]

    def _directive_generation_spec(self):
        return [
            {
                "event": "on_write",
                "key": "pay_bank_trigger",
                "field": "state",
                "from": "draft",
                "to": "in_process",
                "use_record_template_group": True,
                "mode": "create_once",
                # Только для исходящих платежей
                "domain": [("payment_type", "=", "outbound")],
            }
        ]

    def action_bank_gateway_response(self, payload: dict):
        for pay in self:
            bank_ref = f"REF-{pay.id}-X99"

            pay.message_post(
                body=f"Bank Gateway: Платеж отправлен в банк."
                     f"Bank Reference: {bank_ref}"
                     f"Комиссия агента: 0.00 у.е."
            )
        return True