-- Migration: Create delivery_addresses table for shop owners
-- Run this migration to create the delivery_addresses table

CREATE TABLE IF NOT EXISTS delivery_addresses ( 
  id INT AUTO_INCREMENT PRIMARY KEY,
  shop_owner_db_id BIGINT NOT NULL,
  shop_owner_user_id VARCHAR(255) NOT NULL,
  address_label VARCHAR(100) NULL COMMENT 'e.g., Home, Shop, Warehouse',
  street_address TEXT NOT NULL,
  street VARCHAR(255) NULL,
  village VARCHAR(255) NULL,
  district VARCHAR(255) NOT NULL,
  pincode VARCHAR(20) NULL,
  is_default TINYINT(1) DEFAULT 0 COMMENT '1 if this is the default address',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_shop_owner_db_id (shop_owner_db_id),
  INDEX idx_shop_owner_user_id (shop_owner_user_id),
  INDEX idx_is_default (is_default),
  FOREIGN KEY (shop_owner_db_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
