const { DataTypes } = require("sequelize");
const sequelize = require("../config/database");

const Address = sequelize.define(
  "Address",
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    label: {
      type: DataTypes.STRING(50),
      allowNull: false, // e.g. "Home", "Office"
      defaultValue: "Home",
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false, // Receiver Name
    },
    phone: {
      type: DataTypes.STRING(20),
      allowNull: false,
    },
    province: {
      type: DataTypes.STRING(100),
      allowNull: false,
    },
    city: {
      type: DataTypes.STRING(100),
      allowNull: false,
    },
    street: {
      type: DataTypes.TEXT, // Full street address
      allowNull: false,
    },
    detail: {
      type: DataTypes.TEXT, // Notes, landmarks, etc.
      allowNull: true,
    },
    is_primary: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
    },
  },
  {
    timestamps: true,
    tableName: "addresses",
    underscored: true,
  },
);

module.exports = Address;
