# -*- coding: utf-8 -*-
"""STEP 9 — Wizard to open a support modification from a case."""

from odoo import fields, models


class FamilyLawModificationWizard(models.TransientModel):
    _name = "familylaw.modification.wizard"
    _description = "Open Support Modification"

    case_id = fields.Many2one("familylaw.case", required=True)
    current_support_amount = fields.Float(string="Current Monthly Support")
    proposed_support_amount = fields.Float(string="Proposed Monthly Support")
    is_dor_case = fields.Boolean(string="DOR / Title IV-D Case")
    filing_date = fields.Date(default=fields.Date.context_today)
    prior_order_text = fields.Text(string="Prior Order Text (optional)")

    def action_open(self):
        self.ensure_one()
        rec = self.env["familylaw.support.modification"].open_for_case(
            self.case_id,
            self.current_support_amount,
            self.proposed_support_amount,
            is_dor=self.is_dor_case,
            filing_date=self.filing_date,
            prior_order_text=self.prior_order_text or None,
        )
        return {
            "type": "ir.actions.act_window",
            "res_model": "familylaw.support.modification",
            "res_id": rec.id,
            "view_mode": "form",
            "target": "current",
        }
