import carBrandsInit from "./carBrands.js";
import carModelsInit from "./carModels.js";
import bodyTypesInit from "./bodyTypes.js";
import enginesInit from "./engines.js";
import trimsInit from "./trims.js";
import carColorsInit from "./carColors.js";
import transmissionsInit from "./transmissions.js";
import salesInit from "./sales.js";
import carsInit from "./cars.js";
import customersInit from "./customers.js";

export default (sequelize) => {
    carBrandsInit(sequelize);
    carModelsInit(sequelize);
    bodyTypesInit(sequelize);
    enginesInit(sequelize);
    trimsInit(sequelize);
    carColorsInit(sequelize);
    transmissionsInit(sequelize);
    salesInit(sequelize);
    carsInit(sequelize);
    customersInit(sequelize);

    const {
        carBrands,
        carModels,
        engines,
        bodyTypes,
        trims,
        carColors,
        transmissions,
        sales,
        cars,
        customers
    } = sequelize.models;

    carModels.belongsTo(carBrands, {
        foreignKey: 'car_brands_id',
        as: 'carBrands',
    });

    trims.belongsTo(carModels, {
        foreignKey: 'car_models_id',
        as: 'carModels',
    });

    sales.belongsTo(cars, {
        foreignKey: 'cars_id',
        as: 'cars',
    });

    sales.belongsTo(customers, {
        foreignKey: 'customers_id',
        as: 'customers',
    });

    cars.belongsTo(carModels, {
        foreignKey: 'car_models_id',
        as: 'carModels',
    });

    cars.belongsTo(bodyTypes, {
        foreignKey: 'body_types_id',
        as: 'bodyTypes',
    });

    cars.belongsTo(engines, {
        foreignKey: 'engines_id',
        as: 'engines',
    });

    cars.belongsTo(trims, {
        foreignKey: 'trims_id',
        as: 'trims',
    });

    cars.belongsTo(carColors, {
        foreignKey: 'car_colors_id',
        as: 'carColors',
    });

    cars.belongsTo(transmissions, {
        foreignKey: 'transmissions_id',
        as: 'transmissions',
    });
};

