# -*- coding: utf-8 -*-
# Copyright 2024-2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)

from odoo import models, fields
from odoo.exceptions import ValidationError


class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    # =========================================================================
    # LTC PORTAL FORMS
    # =========================================================================

    fc_ltc_form_password = fields.Char(
        string='LTC Form Access Password',
        config_parameter='fusion_ltc_management.ltc_form_password',
        help='Minimum 4 characters. Share with facility staff to access the repair form.',
    )

    def set_values(self):
        super().set_values()
        # Validate LTC form password length
        form_pw = self.fc_ltc_form_password or ''
        if form_pw and len(form_pw.strip()) < 4:
            raise ValidationError(
                'LTC Form Access Password must be at least 4 characters.'
            )
