{
  "table_name": "customer_deliveries",
  "display_name": "配送先マスタ",
  "description": "得意先の配送先情報のインポート。得意先コード＋配送先コードで識別。",
  "type": "relational_table",
  "processor_class": "App\\Services\\Logic\\User\\CsvImport\\SingleTable\\CustomerDeliveryProcessor",
  "call_process_row": true,
  "supported_modes": ["insert", "update", "delete"],
  "import_behavior": "partial_import",

  "key_fields": ["customer_id", "delivery_code"],
  "required_fields": ["customer_id", "delivery_code", "delivery_name"],

  "unique_fields": {
    "composite_unique": {
      "fields": ["customer_id", "delivery_code"],
      "message": "得意先「{customer_code}」の配送先コード「{delivery_code}」は既に登録されています"
    }
  },

  "default_values": {
    "is_active": 1,
    "is_default": 9,
    "is_default_invoice": 9,
    "shipping_type": 1
  },

  "foreign_key_mappings": {
    "customer_code": {
      "target_field": "customer_id",
      "reference_table": "customers",
      "reference_key_column": "customer_code",
      "reference_value_column": "id",
      "reference_condition": "is_active = 1 AND deleted_at IS NULL",
      "required": true,
      "error_message": "得意先コード「{value}」が得意先マスタに存在しないか、無効な状態です。"
    }
  },

  "code_padding": {
    "customer_code": 6,
    "delivery_code": 6
  },

  "composite_key_handling": {
    "update_mode": "composite_unique_key",
    "delete_mode": "composite_unique_key",
    "composite_key_fields": ["customer_id", "delivery_code"]
  },

  "enum_values": {
    "is_default": { "1": "デフォルト", "9": "デフォルト以外" },
    "is_default_invoice": { "1": "デフォルト", "9": "デフォルト以外" },
    "is_active": { "1": "有効", "9": "無効" },
    "shipping_type": { "1": "発送", "2": "直送" }
  },

  "fields": {
    "customer_code": {
      "label": "得意先コード",
      "type": "string",
      "required": true,
      "max_length": 40,
      "validation_rules": ["required", "string", "max:40"],
      "description": "得意先マスタのコード（6桁0埋め）"
    },
    "delivery_code": {
      "label": "配送先コード",
      "type": "string",
      "required": true,
      "max_length": 40,
      "validation_rules": ["required", "string", "max:40"],
      "description": "配送先を識別するコード"
    },
    "delivery_name": {
      "label": "配送先名",
      "type": "string",
      "required": true,
      "max_length": 200,
      "validation_rules": ["required", "string", "max:200"],
      "description": "配送先の名称"
    },
    "delivery_contact": {
      "label": "配送先担当者",
      "type": "string",
      "required": false,
      "max_length": 200,
      "validation_rules": ["string", "max:200"],
      "description": "配送先の担当者名"
    },
    "postal_code": {
      "label": "郵便番号",
      "type": "string",
      "required": false,
      "max_length": 10,
      "validation_rules": ["string", "max:10"],
      "description": "郵便番号"
    },
    "prefecture": {
      "label": "都道府県",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "都道府県"
    },
    "address1": {
      "label": "住所１",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "住所1行目"
    },
    "address2": {
      "label": "住所２",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "住所2行目"
    },
    "address3": {
      "label": "住所３",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "住所3行目"
    },
    "tel": {
      "label": "TEL",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "電話番号"
    },
    "fax": {
      "label": "FAX",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "FAX番号"
    },
    "lead_time_days": {
      "label": "リードタイム",
      "type": "integer",
      "required": false,
      "min_value": 0,
      "validation_rules": ["integer", "min:0"],
      "description": "リードタイム（日数）"
    },
    "shipping_type": {
      "label": "発送区分",
      "type": "integer",
      "required": false,
      "enum": [1, 2],
      "validation_rules": ["integer", "in:1,2"],
      "description": "1=発送, 2=直送"
    },
    "is_default": {
      "label": "デフォルト配送先",
      "type": "integer",
      "required": false,
      "enum": [1, 9],
      "validation_rules": ["integer", "in:1,9"],
      "description": "1=デフォルト, 9=デフォルト以外"
    },
    "is_default_invoice": {
      "label": "デフォルト納品書発行先",
      "type": "integer",
      "required": false,
      "enum": [1, 9],
      "validation_rules": ["integer", "in:1,9"],
      "description": "1=デフォルト, 9=デフォルト以外"
    },
    "is_active": {
      "label": "有効フラグ",
      "type": "integer",
      "required": false,
      "enum": [1, 9],
      "validation_rules": ["integer", "in:1,9"],
      "description": "1=有効, 9=無効"
    },
    "note": {
      "label": "備考",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "備考"
    },
    "shipping_label_delivery_name": {
      "label": "送り状用 配送先名",
      "type": "string",
      "required": false,
      "max_length": 200,
      "validation_rules": ["string", "max:200"],
      "description": "送り状用の配送先名"
    },
    "shipping_label_delivery_contact": {
      "label": "送り状用 配送先担当者",
      "type": "string",
      "required": false,
      "max_length": 200,
      "validation_rules": ["string", "max:200"],
      "description": "送り状用の配送先担当者"
    },
    "shipping_label_postal_code": {
      "label": "送り状用 郵便番号",
      "type": "string",
      "required": false,
      "max_length": 10,
      "validation_rules": ["string", "max:10"],
      "description": "送り状用の郵便番号"
    },
    "shipping_label_prefecture": {
      "label": "送り状用 都道府県",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "送り状用の都道府県"
    },
    "shipping_label_address1": {
      "label": "送り状用 住所１",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "送り状用の住所1行目"
    },
    "shipping_label_address2": {
      "label": "送り状用 住所２",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "送り状用の住所2行目"
    },
    "shipping_label_address3": {
      "label": "送り状用 住所３",
      "type": "string",
      "required": false,
      "max_length": 500,
      "validation_rules": ["string", "max:500"],
      "description": "送り状用の住所3行目"
    },
    "shipping_label_tel": {
      "label": "送り状用 TEL",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "送り状用の電話番号"
    },
    "shipping_label_fax": {
      "label": "送り状用 FAX",
      "type": "string",
      "required": false,
      "max_length": 20,
      "validation_rules": ["string", "max:20"],
      "description": "送り状用のFAX番号"
    },
    "shipping_label_note_1": {
      "label": "送り状 記事1",
      "type": "string",
      "required": false,
      "max_length": 100,
      "validation_rules": ["string", "max:100"],
      "description": "送り状の記事1"
    },
    "shipping_label_note_2": {
      "label": "送り状 記事2",
      "type": "string",
      "required": false,
      "max_length": 100,
      "validation_rules": ["string", "max:100"],
      "description": "送り状の記事2"
    },
    "shipping_label_note_3": {
      "label": "送り状 記事3",
      "type": "string",
      "required": false,
      "max_length": 100,
      "validation_rules": ["string", "max:100"],
      "description": "送り状の記事3"
    },
    "shipping_label_note_4": {
      "label": "送り状 記事4",
      "type": "string",
      "required": false,
      "max_length": 100,
      "validation_rules": ["string", "max:100"],
      "description": "送り状の記事4"
    },
    "shipping_label_note_5": {
      "label": "送り状 記事5",
      "type": "string",
      "required": false,
      "max_length": 100,
      "validation_rules": ["string", "max:100"],
      "description": "送り状の記事5"
    },
    "destination_code": {
      "label": "社･店コード",
      "type": "string",
      "required": false,
      "max_length": 50,
      "validation_rules": ["string", "max:50"],
      "description": "社・店コード"
    },
    "yodobashi_edi_delivery_code": {
      "label": "ヨドバシEDI納品先コード",
      "type": "string",
      "required": false,
      "max_length": 10,
      "validation_rules": ["string", "max:10"],
      "description": "ヨドバシEDI納品先コード"
    }
  },

  "field_labels": {
    "customer_code": "得意先コード",
    "delivery_code": "配送先コード",
    "delivery_name": "配送先名",
    "delivery_contact": "配送先担当者",
    "postal_code": "郵便番号",
    "prefecture": "都道府県",
    "address1": "住所１",
    "address2": "住所２",
    "address3": "住所３",
    "tel": "TEL",
    "fax": "FAX",
    "lead_time_days": "リードタイム",
    "shipping_type": "発送区分",
    "is_default": "デフォルト配送先",
    "is_default_invoice": "デフォルト納品書発行先",
    "is_active": "有効フラグ",
    "note": "備考",
    "shipping_label_delivery_name": "送り状用 配送先名",
    "shipping_label_delivery_contact": "送り状用 配送先担当者",
    "shipping_label_postal_code": "送り状用 郵便番号",
    "shipping_label_prefecture": "送り状用 都道府県",
    "shipping_label_address1": "送り状用 住所１",
    "shipping_label_address2": "送り状用 住所２",
    "shipping_label_address3": "送り状用 住所３",
    "shipping_label_tel": "送り状用 TEL",
    "shipping_label_fax": "送り状用 FAX",
    "shipping_label_note_1": "送り状 記事1",
    "shipping_label_note_2": "送り状 記事2",
    "shipping_label_note_3": "送り状 記事3",
    "shipping_label_note_4": "送り状 記事4",
    "shipping_label_note_5": "送り状 記事5",
    "destination_code": "社･店コード",
    "yodobashi_edi_delivery_code": "ヨドバシEDI納品先コード"
  },

  "error_codes": {
    "E001": {
      "type": "format",
      "message": "必須カラム「{column}」がCSVに含まれていません"
    },
    "E002": {
      "type": "master",
      "message": "得意先コード「{code}」が得意先マスタに存在しません"
    },
    "E003": {
      "type": "validation",
      "message": "{field}は{expected}で入力してください"
    },
    "E004": {
      "type": "duplicate",
      "message": "得意先「{customer_code}」には既にデフォルト配送先が設定されています"
    },
    "E005": {
      "type": "type",
      "message": "データ型エラー"
    },
    "E006": {
      "type": "duplicate",
      "message": "複合キー重複エラー"
    },
    "E007": {
      "type": "not_found",
      "message": "更新/削除対象のレコードが見つかりません"
    }
  },

  "csv_format_example": {
    "description": "配送先マスタインポート用CSVフォーマット",
    "headers": [
      "得意先コード",
      "配送先コード",
      "配送先名",
      "配送先担当者",
      "郵便番号",
      "都道府県",
      "住所１",
      "住所２",
      "TEL",
      "FAX",
      "デフォルト配送先",
      "デフォルト納品書発行先",
      "リードタイム",
      "発送区分",
      "有効フラグ",
      "送り状用 配送先名",
      "送り状用 配送先担当者",
      "送り状用 郵便番号",
      "送り状用 都道府県",
      "送り状用 住所１",
      "送り状用 住所２",
      "送り状用 住所３",
      "送り状用 TEL",
      "送り状用 FAX"
    ],
    "sample_data": [
      ["#", "※この行と次の行は削除してからインポートしてください。【必須】: 得意先コード, 配送先コード, 配送先名", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
      ["#", "デフォルト配送先: 1=デフォルト, 9=デフォルト以外 / デフォルト納品書発行先: 1=デフォルト, 9=デフォルト以外 / 発送区分: 1=発送, 2=直送 / 有効フラグ: 1=有効, 9=無効", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
      ["000001", "000001", "本社", "田中太郎", "100-0001", "東京都", "千代田区丸の内1-1-1", "ビル5F", "03-1234-5678", "03-1234-5679", "1", "1", "3", "1", "1", "", "", "", "", "", "", "", "", ""],
      ["000001", "000002", "大阪支店", "山田花子", "530-0001", "大阪府", "大阪市北区梅田1-1-1", "", "06-1234-5678", "", "9", "9", "5", "2", "1", "", "", "", "", "", "", "", "", ""],
      ["000002", "000001", "本社", "佐藤一郎", "460-0001", "愛知県", "名古屋市中区栄1-1-1", "", "052-123-4567", "", "1", "1", "4", "1", "1", "", "", "", "", "", "", "", "", ""]
    ]
  }
}
