'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    // Create build_cleanup_config table
    await queryInterface.createTable('build_cleanup_config', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
      },
      enabled: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        allowNull: false,
      },
      retention_days: {
        type: Sequelize.INTEGER,
        defaultValue: 30,
        allowNull: false,
      },
      cron_schedule: {
        type: Sequelize.STRING(100),
        defaultValue: '0 0 * * *',
        allowNull: false,
      },
      last_run_at: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      last_run_stats: {
        type: Sequelize.JSONB,
        allowNull: true,
      },
      created_at: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
        allowNull: false,
      },
      updated_at: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
        allowNull: false,
      },
    });

    // Insert default configuration row
    await queryInterface.bulkInsert('build_cleanup_config', [
      {
        id: '00000000-0000-0000-0000-000000000001',
        enabled: false,
        retention_days: 30,
        cron_schedule: '0 0 * * *',
        last_run_at: null,
        last_run_stats: null,
        created_at: new Date(),
        updated_at: new Date(),
      },
    ]);
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('build_cleanup_config');
  },
};
