<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Validation\StrictRules\CreditCardRules;
use CodeIgniter\Validation\StrictRules\FileRules;
use CodeIgniter\Validation\StrictRules\FormatRules;
use CodeIgniter\Validation\StrictRules\Rules;

class Validation extends BaseConfig
{
    // --------------------------------------------------------------------
    // Setup
    // --------------------------------------------------------------------

    /**
     * Stores the classes that contain the
     * rules that are available.
     *
     * @var list<string>
     */
    public array $ruleSets = [
        Rules::class,
        FormatRules::class,
        FileRules::class,
        CreditCardRules::class,
    ];

    /**
     * Specifies the views that are used to display the
     * errors.
     *
     * @var array<string, string>
     */
    public array $templates = [
        'list'   => 'CodeIgniter\Validation\Views\list',
        'single' => 'CodeIgniter\Validation\Views\single',
    ];

    // --------------------------------------------------------------------
    // Rules
    // --------------------------------------------------------------------

    /**
     * @var array<string, array<string, string>>
     */
    public array $child = [
        'first_name' => 'required|min_length[2]|max_length[100]',
        'last_name' => 'required|min_length[2]|max_length[100]',
        'birth_date' => 'permit_empty|valid_date[Y-m-d]',
        'gender' => 'permit_empty|in_list[male,female]',
        'academy_level_id' => 'permit_empty|is_not_unique[academy_levels.id]',
        'academy_group_id' => 'permit_empty|is_not_unique[academy_groups.id]',
        'primary_coach_id' => 'permit_empty|is_not_unique[coaches.id]',
        'first_class_at' => 'permit_empty|valid_date[Y-m-d]',
        'status' => 'required|in_list[active,pause,left]',
        'has_siblings' => 'required|in_list[0,1]',
        'notes' => 'permit_empty|max_length[4000]',
        'guardian_name' => 'required|min_length[3]|max_length[150]',
        'guardian_phone' => 'permit_empty|max_length[30]',
        'guardian_email' => 'permit_empty|valid_email|max_length[120]',
    ];

    /**
     * @var array<string, array<string, string>>
     */
    public array $coach = [
        'full_name' => 'required|min_length[3]|max_length[150]',
        'display_role' => 'required|max_length[100]',
        'phone' => 'permit_empty|max_length[30]',
        'email' => 'required|valid_email|max_length[120]',
        'avatar_path' => 'permit_empty|max_length[255]',
        'is_active' => 'required|in_list[0,1]',
        'notes' => 'permit_empty|max_length[4000]',
        'username' => 'required|min_length[3]|max_length[30]',
    ];

    /**
     * @var array<string, array<string, string>>
     */
    public array $academyGroup = [
        'name' => 'required|min_length[2]|max_length[100]',
        'code' => 'required|min_length[2]|max_length[50]',
        'academy_level_id' => 'permit_empty|is_not_unique[academy_levels.id]',
        'primary_coach_id' => 'permit_empty|is_not_unique[coaches.id]',
        'schedule_summary' => 'permit_empty|max_length[255]',
        'status' => 'required|in_list[active,inactive]',
        'capacity' => 'required|integer|greater_than[0]|less_than_equal_to[40]',
    ];

    /**
     * @var array<string, array<string, string>>
     */
    public array $academyLevel = [
        'name' => 'required|min_length[2]|max_length[100]',
        'slug' => 'required|min_length[2]|max_length[100]|alpha_dash',
        'sort_order' => 'required|integer|greater_than_equal_to[1]',
        'color_hex' => 'permit_empty|regex_match[/^#[0-9A-Fa-f]{6}$/]',
        'internal_description' => 'permit_empty|max_length[4000]',
        'parent_description' => 'permit_empty|max_length[4000]',
        'benchmark_minimum' => 'permit_empty|decimal',
        'benchmark_target' => 'permit_empty|decimal',
        'promotion_rules' => 'permit_empty|max_length[4000]',
    ];

    /**
     * @var array<string, array<string, string>>
     */
    public array $attendanceSession = [
        'academy_group_id' => 'required|is_not_unique[academy_groups.id]',
        'coach_id' => 'permit_empty|is_not_unique[coaches.id]',
        'session_date' => 'required|valid_date[Y-m-d]',
        'start_time' => 'permit_empty|regex_match[/^(?:[01]\d|2[0-3]):[0-5]\d$/]',
        'end_time' => 'permit_empty|regex_match[/^(?:[01]\d|2[0-3]):[0-5]\d$/]',
        'status' => 'required|in_list[scheduled,completed,cancelled,recovery]',
        'cancelled_reason' => 'permit_empty|max_length[4000]',
        'recovery_for_session_id' => 'permit_empty|is_not_unique[attendance_sessions.id]',
        'notes' => 'permit_empty|max_length[4000]',
    ];

    /**
     * @var array<string, array<string, string>>
     */
    public array $evaluation = [
        'evaluation_date' => 'required|valid_date[Y-m-d]',
        'evaluator_coach_id' => 'permit_empty|is_not_unique[coaches.id]',
        'notes' => 'permit_empty|max_length[4000]',
    ];
}
