{
  "display_name": "得意先別政策単価マスタ",
  "description": "得意先別の政策単価データをインポート。価格改定時は旧単価の自動終了に対応。",
  "type": "single_table",
  "processor_class": "App\\Services\\Logic\\User\\CsvImport\\SingleTable\\CustomerProductPolicyPriceProcessor",
  "call_process_row": false,
  "import_behavior": "all_or_nothing",
  "supported_modes": ["insert"],
  "fields": {
    "action_type": {
      "label": "処理区分",
      "type": "integer",
      "required": true,
      "enum": [1, 2, 3, 4],
      "validation_rules": [
        "required",
        "integer",
        "in:1,2,3,4"
      ],
      "description": "1=新規/価格改定, 2=期間限定価格追加, 3=更新, 4=削除"
    },
    "customer_code": {
      "label": "得意先コード",
      "type": "string",
      "required": true,
      "max_length": 50,
      "validation_rules": [
        "required",
        "string",
        "max:50"
      ],
      "description": "得意先マスタのコード"
    },
    "product_code": {
      "label": "商品コード",
      "type": "string",
      "required": true,
      "max_length": 40,
      "validation_rules": [
        "required",
        "string",
        "max:40"
      ],
      "description": "商品マスタのコード"
    },
    "unit_price": {
      "label": "政策単価",
      "type": "decimal",
      "required": true,
      "required_unless": "action_type:4",
      "min_value": 0,
      "validation_rules": [
        "numeric",
        "min:0"
      ],
      "description": "政策単価（削除時は不要）"
    },
    "valid_from": {
      "label": "適用開始日",
      "type": "date",
      "required": true,
      "format": "Y-m-d",
      "validation_rules": [
        "required",
        "date"
      ],
      "description": "適用開始日（YYYY-MM-DD形式）"
    },
    "valid_to": {
      "label": "適用終了日",
      "type": "date",
      "required": false,
      "format": "Y-m-d",
      "validation_rules": [
        "date"
      ],
      "description": "適用終了日（YYYY-MM-DD形式、空欄で無期限）"
    },
    "note": {
      "label": "備考",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": [
        "string",
        "max:500"
      ],
      "description": "備考（任意）"
    }
  },
  "code_padding": {
    "customer_code": 6,
    "product_code": 8
  },
  "foreign_key_mappings": {
    "customer_code": {
      "target_field": "customer_id",
      "reference_table": "customers",
      "reference_key_column": "customer_code",
      "reference_value_column": "id",
      "required": true,
      "error_message": "得意先コード「{value}」が見つかりません"
    },
    "product_code": {
      "target_field": "product_id",
      "reference_table": "products",
      "reference_key_column": "product_code",
      "reference_value_column": "id",
      "required": true,
      "error_message": "商品コード「{value}」が見つかりません"
    }
  },
  "business_rules": {
    "unit_price_required_for_non_delete": {
      "rule": "if action_type != 4 then unit_price required",
      "error_message": "政策単価は必須です（削除時を除く）"
    },
    "valid_to_after_valid_from": {
      "rule": "valid_to >= valid_from",
      "error_message": "適用終了日は適用開始日以降を指定してください"
    }
  },
  "error_codes": {
    "E001": {
      "type": "format",
      "message": "必須カラム「{column}」がCSVに含まれていません"
    },
    "E002": {
      "type": "master",
      "message": "得意先コード「{code}」が見つかりません"
    },
    "E003": {
      "type": "master",
      "message": "商品コード「{code}」が見つかりません"
    },
    "E005": {
      "type": "required",
      "message": "{field}は必須です"
    },
    "E006": {
      "type": "consistency",
      "message": "適用終了日は適用開始日以降を指定してください"
    },
    "E009": {
      "type": "process",
      "message": "更新/削除対象のレコードが見つかりません"
    },
    "E010": {
      "type": "value",
      "message": "政策単価は0以上を指定してください"
    },
    "E011": {
      "type": "value",
      "message": "処理区分は1〜4のいずれかを指定してください"
    }
  },
  "csv_format_example": {
    "description": "得意先別政策単価インポート用CSVフォーマット",
    "headers": [
      "処理区分",
      "得意先コード",
      "商品コード",
      "政策単価",
      "適用開始日",
      "適用終了日",
      "備考"
    ],
    "sample_data": [
      ["#", "処理区分: 1=新規/価格改定, 2=期間限定価格追加, 3=更新, 4=削除", "", "", "", "", ""],
      ["1", "024081", "00004811", "1500", "2025-04-01", "", "【処理区分1】新規/価格改定：既存単価を終了し新単価を登録"],
      ["2", "024081", "00004811", "1200", "2025-10-01", "2025-10-31", "【処理区分2】期間限定価格：既存単価に影響せず追加"],
      ["3", "024081", "00004811", "1480", "2025-04-01", "", "【処理区分3】更新：既存レコードの単価を変更"],
      ["4", "024081", "00004811", "", "2025-04-01", "", "【処理区分4】削除：既存レコードを物理削除"]
    ]
  }
}
