# -*- coding: utf-8 -*-

from odoo import api, fields, models, _


class ConfigFlowStep(models.Model):
    _name = 'fusion.wc.config.flow.step'
    _description = 'Configuration Flow Form Step'
    _order = 'sequence, id'

    flow_id = fields.Many2one('fusion.wc.config.flow', string='Flow',
        required=True, ondelete='cascade', index=True)
    sequence = fields.Integer(string='Sequence', default=10)
    name = fields.Char(string='Step Name', required=True,
        help='Display name shown in the step indicator, e.g. "Client Info", "Measurements"')

    step_type = fields.Selection([
        ('client_info', 'Client Information'),
        ('measurements', 'Measurements'),
        ('product_select', 'Product Selection'),
        ('options', 'Options & Accessories'),
        ('review', 'Review & Submit'),
        ('custom', 'Custom Fields'),
    ], string='Step Type', required=True, default='custom')

    icon = fields.Char(string='Icon', default='fa-circle',
        help='FontAwesome icon class for the step indicator')

    # For product_select / options steps — which section to filter by
    section_id = fields.Many2one('fusion.wc.section', string='Section',
        help='Link to a wheelchair/equipment section for product filtering')
    section_code = fields.Char(string='Section Code',
        help='Alternative to section_id — match section by code. '
             'Supports comma-separated codes for options steps.')

    # For measurements / custom steps — JSON field definitions
    fields_json = fields.Text(string='Field Definitions (JSON)',
        help='JSON array of field definitions for dynamic rendering. '
             'Each entry: {"name": "field_name", "label": "Display Label", '
             '"type": "float|integer|selection|char|text|boolean", '
             '"unit": "inches", "required": true, '
             '"options": [["value", "Label"], ...]}')

    help_text = fields.Text(string='Help Text',
        help='Instructions displayed at the top of this step')
    is_required = fields.Boolean(string='Required', default=True,
        help='If true, this step must be completed before proceeding')
