use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .alter_table(
                Table::alter()
                    .table(ReminderOffset::Table)
                    .add_column(ColumnDef::new(ReminderOffset::BarkTitle).string().null())
                    .add_column(ColumnDef::new(ReminderOffset::BarkSubtitle).string().null())
                    .add_column(ColumnDef::new(ReminderOffset::BarkBodyMarkdown).text().null())
                    .add_column(ColumnDef::new(ReminderOffset::BarkLevel).string().null())
                    .add_column(ColumnDef::new(ReminderOffset::BarkIcon).string().null())
                    .to_owned(),
            )
            .await?;
        Ok(())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .alter_table(
                Table::alter()
                    .table(ReminderOffset::Table)
                    .drop_column(ReminderOffset::BarkTitle)
                    .drop_column(ReminderOffset::BarkSubtitle)
                    .drop_column(ReminderOffset::BarkBodyMarkdown)
                    .drop_column(ReminderOffset::BarkLevel)
                    .drop_column(ReminderOffset::BarkIcon)
                    .to_owned(),
            )
            .await?;
        Ok(())
    }
}

#[derive(DeriveIden)]
enum ReminderOffset {
    Table,
    BarkTitle,
    BarkSubtitle,
    BarkBodyMarkdown,
    BarkLevel,
    BarkIcon,
}
