{
    "table_name": "users",
    "display_name": "社員マスタ",
    "description": "社員情報のインポート。パスワードは自動的にハッシュ化されます。",
    "type": "relational_table",
    "processor_class": "App\\Services\\Logic\\User\\CsvImport\\SingleTable\\UserProcessor",
    "call_process_row": true,
    "supported_modes": [
        "insert",
        "update"
    ],
    "import_behavior": "all_or_nothing",
    "key_fields": [
        "id",
        "user_code"
    ],
    "required_fields": [
        "user_code",
        "family_name",
        "role_id"
    ],
    "default_values": {
        "notify_enabled": 1,
        "is_account_locked": 1,
        "login_failure_count": 0
    },
    "unique_fields": {
        "user_code": {
            "table": "users",
            "column": "user_code",
            "message": "社員コード「{user_code}」は既に登録されています"
        },
        "email": {
            "table": "users",
            "column": "email",
            "message": "メールアドレス「{email}」は既に登録されています"
        }
    },
    "foreign_key_mappings": {
        "department_name": {
            "target_field": "department_id",
            "reference_table": "departments",
            "reference_key_column": "department_name",
            "reference_value_column": "id",
            "reference_condition": "is_active = 1",
            "required": false,
            "error_message": "指定された部門名「{value}」が部門マスタに存在しないか、無効な状態です。"
        },
        "warehouse_code": {
            "target_field": "warehouse_id",
            "reference_table": "warehouses",
            "reference_key_column": "warehouse_code",
            "reference_value_column": "id",
            "reference_condition": "is_active = 1",
            "required": false,
            "error_message": "指定された拠点コード「{value}」が拠点マスタに存在しないか、無効な状態です。"
        },
        "role_name": {
            "target_field": "role_id",
            "reference_table": "roles",
            "reference_key_column": "role_name",
            "reference_value_column": "id",
            "required": true,
            "error_message": "指定された権限名「{value}」が権限マスタに存在しません。"
        }
    },
    "field_labels": {
        "id": "ID",
        "user_code": "社員コード",
        "family_name": "姓",
        "given_name": "名",
        "name_kana": "氏名（カナ）",
        "email": "ログインID(E-mail)",
        "password": "パスワード",
        "department_id": "所属部門ID",
        "department_name": "部門名",
        "warehouse_id": "拠点ID",
        "warehouse_code": "拠点コード",
        "position_name": "役職名",
        "role_id": "権限ロールID",
        "role_name": "権限名",
        "is_sales_user": "営業担当者フラグ",
        "is_active": "有効フラグ",
        "mobile_phone_number": "携帯電話番号",
        "work_phone_number": "勤務先電話",
        "password_change_required": "パスワード変更必須フラグ",
        "two_factor_enabled": "二要素認証有効フラグ",
        "note": "備考",
        "created_by": "登録者ID",
        "updated_by": "更新者ID",
        "created_at": "登録日",
        "updated_at": "更新日",
        "deleted_at": "削除日"
    },
    "field_types": {
        "id": "bigint",
        "user_code": "varchar",
        "family_name": "varchar",
        "given_name": "varchar",
        "name_kana": "varchar",
        "email": "varchar",
        "password": "varchar",
        "department_id": "bigint",
        "department_name": "varchar",
        "warehouse_id": "bigint",
        "warehouse_code": "varchar",
        "position_name": "varchar",
        "role_id": "bigint",
        "role_name": "varchar",
        "is_sales_user": "integer",
        "is_active": "integer",
        "mobile_phone_number": "varchar",
        "work_phone_number": "varchar",
        "password_change_required": "integer",
        "two_factor_enabled": "integer",
        "note": "varchar",
        "created_by": "bigint",
        "updated_by": "bigint",
        "created_at": "timestamp",
        "updated_at": "timestamp",
        "deleted_at": "timestamp"
    },
    "enum_values": {
        "is_sales_user": {
            "1": "営業担当",
            "9": "営業担当以外"
        },
        "is_active": {
            "1": "有効",
            "9": "無効"
        },
        "password_change_required": {
            "1": "必須",
            "9": "不要"
        },
        "two_factor_enabled": {
            "1": "有効",
            "9": "無効"
        }
    },
    "validation_rules": {
        "user_code": {
            "required": true,
            "max_length": 40,
            "message": "社員コードは必須です。40文字以内で入力してください。"
        },
        "family_name": {
            "required": true,
            "max_length": 100,
            "message": "姓は必須です。100文字以内で入力してください。"
        },
        "given_name": {
            "max_length": 100,
            "message": "名は100文字以内で入力してください。"
        },
        "name_kana": {
            "max_length": 200,
            "message": "氏名（カナ）は200文字以内で入力してください。"
        },
        "email": {
            "required": false,
            "max_length": 255,
            "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
            "message": "有効なメールアドレス形式で入力してください。"
        },
        "password": {
            "required": false,
            "message": "パスワードを入力する場合は値を設定してください。"
        },
        "role_id": {
            "required": true,
            "exists": {
                "table": "roles",
                "column": "id"
            }
        },
        "is_sales_user": {
            "enum": [1, 9],
            "message": "営業担当者フラグは1（営業担当）または9（営業担当以外）で入力してください。"
        },
        "is_active": {
            "enum": [1, 9],
            "message": "有効フラグは1（有効）または9（無効）で入力してください。"
        },
        "password_change_required": {
            "enum": [1, 9],
            "message": "パスワード変更必須フラグは1（必須）または9（不要）で入力してください。"
        },
        "two_factor_enabled": {
            "enum": [1, 9],
            "message": "二要素認証有効フラグは1（有効）または9（無効）で入力してください。"
        },
        "mobile_phone_number": {
            "max_length": 20,
            "message": "携帯電話番号は20文字以内で入力してください。"
        },
        "work_phone_number": {
            "max_length": 20,
            "message": "勤務先電話は20文字以内で入力してください。"
        },
        "position_name": {
            "max_length": 100,
            "message": "役職名は100文字以内で入力してください。"
        },
        "note": {
            "max_length": 500,
            "message": "備考は500文字以内で入力してください。"
        }
    },
    "business_rules": {
        "unique_user_code": {
            "description": "社員コードは一意である必要があります",
            "validation": "required"
        },
        "unique_email": {
            "description": "メールアドレスは一意である必要があります（入力された場合のみチェック）",
            "validation": "conditional"
        },
        "password_hash": {
            "description": "パスワードはDB保存時にハッシュ化されます（入力された場合のみ）",
            "validation": "conditional"
        },
        "role_required": {
            "description": "権限ロールは必須です",
            "validation": "required"
        }
    },
    "import_notes": {
        "user_code": "社員コードは一意である必要があります",
        "email": "メールアドレスは一意である必要があります。空欄の場合はログイン不可のユーザーとして登録されます。",
        "password": "パスワードはDB保存時に自動的にハッシュ化されます。空欄の場合はログイン不可のユーザーとして登録されます。",
        "department_name": "部門名は部門マスタに登録されている名称を入力してください",
        "warehouse_code": "拠点コードは拠点マスタに登録されているコードを入力してください",
        "role_name": "権限名は権限マスタに登録されている名称を入力してください（必須）",
        "flags": "フラグ項目は1または9で入力してください（1:有効/はい、9:無効/いいえ）"
    },
    "sample_data": {
        "headers": [
            "社員コード",
            "姓",
            "名",
            "氏名（カナ）",
            "ログインID(E-mail)",
            "パスワード",
            "部門名",
            "拠点コード",
            "役職名",
            "権限名",
            "営業担当者フラグ",
            "有効フラグ",
            "携帯電話番号",
            "勤務先電話",
            "パスワード変更必須フラグ",
            "二要素認証有効フラグ",
            "備考"
        ],
        "rows": [
            [
                "U001",
                "山田",
                "太郎",
                "ヤマダタロウ",
                "yamada@example.com",
                "Password123!",
                "営業部",
                "WH001",
                "課長",
                "一般",
                "1",
                "1",
                "090-1234-5678",
                "03-1234-5678",
                "1",
                "9",
                "サンプルユーザー"
            ],
            [
                "U002",
                "佐藤",
                "花子",
                "サトウハナコ",
                "sato@example.com",
                "Password456!",
                "経理部",
                "WH001",
                "主任",
                "管理者",
                "9",
                "1",
                "090-9876-5432",
                "",
                "9",
                "9",
                ""
            ]
        ]
    },
    "csv_format_example": {
        "description": "社員マスタインポート用CSVフォーマット",
        "headers": [
            "社員コード",
            "姓",
            "名",
            "氏名（カナ）",
            "ログインID(E-mail)",
            "パスワード",
            "部門名",
            "拠点コード",
            "役職名",
            "権限名",
            "営業担当者フラグ",
            "有効フラグ",
            "携帯電話番号",
            "勤務先電話",
            "パスワード変更必須フラグ",
            "二要素認証有効フラグ",
            "備考"
        ],
        "sample_data": [
            ["# 社員コードは一意である必要があります", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["# パスワードは自動的にハッシュ化されます", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["# 権限名は権限マスタに登録されている名称を入力してください（必須）", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["# フラグ項目: 1=はい/有効, 9=いいえ/無効", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["U001", "山田", "太郎", "ヤマダタロウ", "yamada@example.com", "Password123!", "営業部", "WH001", "課長", "一般", "1", "1", "090-1234-5678", "03-1234-5678", "1", "9", "サンプルユーザー"],
            ["U002", "佐藤", "花子", "サトウハナコ", "sato@example.com", "Password456!", "経理部", "WH001", "主任", "管理者", "9", "1", "090-9876-5432", "", "9", "9", ""]
        ]
    }
}
