{
  "display_name": "得意先・配送先特別単価マスタ",
  "description": "得意先・配送先別の単価データをインポート。価格改定時は旧単価の自動終了に対応。",
  "processor_class": "App\\Services\\Logic\\User\\CsvImport\\SingleTable\\CustomerDeliveryProductPriceProcessor",
  "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": "得意先マスタのコード"
    },
    "delivery_code": {
      "label": "配送先コード",
      "type": "string",
      "required": false,
      "max_length": 50,
      "validation_rules": [
        "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": "単価（削除時は不要）"
    },
    "quantity_condition_type": {
      "label": "数量条件",
      "type": "integer",
      "required": true,
      "enum": [1, 2, 3],
      "validation_rules": [
        "required",
        "integer",
        "in:1,2,3"
      ],
      "description": "1=指定なし, 2=ロット単価, 3=範囲指定"
    },
    "specified_quantity": {
      "label": "指定数量",
      "type": "integer",
      "required": false,
      "required_if": "quantity_condition_type:2",
      "min_value": 1,
      "validation_rules": [
        "integer",
        "min:1"
      ],
      "description": "数量条件=2（ロット単価）の場合に必須"
    },
    "min_quantity": {
      "label": "数量下限",
      "type": "integer",
      "required": false,
      "required_if": "quantity_condition_type:3",
      "min_value": 0,
      "validation_rules": [
        "integer",
        "min:0"
      ],
      "description": "数量条件=3（範囲指定）の場合に必須"
    },
    "max_quantity": {
      "label": "数量上限",
      "type": "integer",
      "required": false,
      "required_if": "quantity_condition_type:3",
      "min_value": 1,
      "validation_rules": [
        "integer",
        "min:1"
      ],
      "description": "数量条件=3（範囲指定）の場合に必須"
    },
    "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,
    "delivery_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}」が見つかりません"
    },
    "delivery_code": {
      "target_field": "delivery_id",
      "reference_table": "customer_deliveries",
      "reference_key_column": "delivery_code",
      "reference_value_column": "id",
      "reference_condition": "customer_id = :resolved_customer_id",
      "required": false,
      "allow_null": true,
      "error_message": "得意先「{customer_code}」の配送先コード「{value}」が見つかりません"
    }
  },
  "business_rules": {
    "unit_price_required_for_non_delete": {
      "rule": "if action_type != 4 then unit_price required",
      "error_message": "単価は必須です（削除時を除く）"
    },
    "specified_quantity_required_for_lot": {
      "rule": "if quantity_condition_type = 2 then specified_quantity required",
      "error_message": "ロット単価の場合、指定数量は必須です"
    },
    "min_max_required_for_range": {
      "rule": "if quantity_condition_type = 3 then min_quantity and max_quantity required",
      "error_message": "範囲指定の場合、数量下限・上限は必須です"
    },
    "valid_to_after_valid_from": {
      "rule": "valid_to >= valid_from",
      "error_message": "適用終了日は適用開始日以降を指定してください"
    },
    "max_quantity_gte_min_quantity": {
      "rule": "max_quantity >= min_quantity",
      "error_message": "数量上限は数量下限以上を指定してください"
    }
  },
  "error_codes": {
    "E001": {
      "type": "format",
      "message": "必須カラム「{column}」がCSVに含まれていません"
    },
    "E002": {
      "type": "master",
      "message": "得意先コード「{code}」が見つかりません"
    },
    "E003": {
      "type": "master",
      "message": "商品コード「{code}」が見つかりません"
    },
    "E004": {
      "type": "master",
      "message": "得意先「{customer_code}」の配送先コード「{code}」が見つかりません"
    },
    "E005": {
      "type": "required",
      "message": "{field}は必須です"
    },
    "E006": {
      "type": "consistency",
      "message": "適用終了日は適用開始日以降を指定してください"
    },
    "E007": {
      "type": "consistency",
      "message": "数量上限は数量下限以上を指定してください"
    },
    "E008": {
      "type": "overlap",
      "message": "同一条件で有効期間が重複するレコードが存在します"
    },
    "E009": {
      "type": "process",
      "message": "更新/削除対象のレコードが見つかりません"
    },
    "E010": {
      "type": "value",
      "message": "単価は0以上を指定してください"
    },
    "E011": {
      "type": "value",
      "message": "処理区分は1〜4のいずれかを指定してください"
    },
    "E012": {
      "type": "value",
      "message": "数量条件は1〜3のいずれかを指定してください"
    }
  },
  "csv_format_example": {
    "description": "得意先・配送先別単価インポート用CSVフォーマット",
    "headers": [
      "処理区分",
      "得意先コード",
      "配送先コード",
      "商品コード",
      "単価",
      "数量条件",
      "指定数量",
      "数量下限",
      "数量上限",
      "適用開始日",
      "適用終了日",
      "備考"
    ],
    "sample_data": [
      ["#", "処理区分: 1=新規/価格改定, 2=期間限定価格追加, 3=更新, 4=削除", "", "", "", "", "", "", "", "", "", ""],
      ["#", "数量条件: 1=指定なし, 2=ロット単価(指定数量), 3=範囲指定(数量下限〜上限)", "", "", "", "", "", "", "", "", "", ""],
      ["1", "024081", "", "00004811", "1500", "1", "", "", "", "2025-04-01", "", "【処理区分1】新規/価格改定：既存単価を終了し新単価を登録"],
      ["1", "024081", "", "00004811", "1400", "2", "100", "", "", "2025-04-01", "", "【処理区分1】100個ロット単価を新規登録"],
      ["2", "024081", "", "00004811", "1200", "1", "", "", "", "2025-10-01", "2025-10-31", "【処理区分2】期間限定価格：既存単価に影響せず追加"],
      ["1", "024081", "D001", "00004811", "1450", "3", "", "50", "99", "2025-04-01", "", "【処理区分1】配送先D001向け範囲単価(50〜99個)"],
      ["3", "024081", "", "00004811", "1480", "1", "", "", "", "2025-04-01", "", "【処理区分3】更新：既存レコードの単価を変更"],
      ["4", "024081", "", "00004811", "", "1", "", "", "", "2025-04-01", "", "【処理区分4】削除：既存レコードを物理削除"]
    ]
  }
}
