# -*- coding: utf-8 -*-
"""STEP 10 — Wizard to open an emergency motion from a case (fast-path)."""

from odoo import fields, models


class FamilyLawEmergencyWizard(models.TransientModel):
    _name = "familylaw.emergency.wizard"
    _description = "Open Emergency Motion"

    case_id = fields.Many2one("familylaw.case", required=True)
    motion_type = fields.Selection(
        selection=[
            ("pickup_order", "Pick-Up Order"),
            ("temporary_custody", "Emergency Temporary Custody"),
            ("prevent_removal", "Prevent Removal from Jurisdiction"),
            ("other", "Other Emergency Relief"),
        ],
        default="pickup_order",
        required=True,
    )
    have_existing_order = fields.Boolean(string="Existing Order to Enforce?")
    child_id = fields.Many2one("familylaw.child", string="Child")
    existing_order_reference = fields.Char(string="Existing Order Reference")
    basis = fields.Text(string="Sworn Basis (no existing order)")

    def action_open(self):
        self.ensure_one()
        motion = self.env["familylaw.emergency.motion"].open_for_case(
            self.case_id, self.motion_type, self.have_existing_order,
            child=self.child_id or None,
            basis=self.basis or None,
            existing_order_reference=self.existing_order_reference or None,
        )
        return {
            "type": "ir.actions.act_window",
            "res_model": "familylaw.emergency.motion",
            "res_id": motion.id,
            "view_mode": "form",
            "target": "current",
        }
