-- 200_articles.sql
USE blitech_facturation_dev;

CREATE TABLE articles (
  id              CHAR(36)     NOT NULL,
  id_entite       CHAR(36)     NOT NULL,

  code            VARCHAR(50)  DEFAULT NULL,  -- 'ATELIER_100', etc.
  libelle         VARCHAR(255) NOT NULL,
  description     TEXT         DEFAULT NULL,

  prix_unitaire_ht DECIMAL(10,2) NOT NULL,
  tva_taux         DECIMAL(5,2)  NOT NULL DEFAULT 0.00,

  actif           TINYINT(1)   NOT NULL DEFAULT 1,

  date_creation   DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,

  PRIMARY KEY (id),

  CONSTRAINT fk_articles_entite
    FOREIGN KEY (id_entite) REFERENCES entites(id)
      ON DELETE RESTRICT ON UPDATE CASCADE,

  UNIQUE KEY uniq_articles_entite_code (id_entite, code)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;
