-- ---------------------------------------------------------------------------
-- Factory-New-Prod — Adresses de facturation (plusieurs par utilisateur)
-- MariaDB 10.11 | utf8mb4_unicode_ci
-- ---------------------------------------------------------------------------

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `billing_addresses` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `user_id` INT NOT NULL,
    `label` VARCHAR(100) NOT NULL COMMENT 'ex. Siège, Agence Paris',
    `company` VARCHAR(255) NULL,
    `address_line1` VARCHAR(255) NOT NULL,
    `address_line2` VARCHAR(255) NULL,
    `postal_code` VARCHAR(20) NOT NULL,
    `city` VARCHAR(100) NOT NULL,
    `country_iso` CHAR(2) NOT NULL DEFAULT 'FR',
    `is_default` TINYINT(1) NOT NULL DEFAULT 0,
    `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `idx_billing_addresses_user_id` (`user_id`),
    CONSTRAINT `fk_billing_addresses_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
