package migrations

import (
	"github.com/akfaiz/migris"
	"github.com/akfaiz/migris/schema"
)

func init() {
	migris.AddMigrationContext(upInsertData, downInsertData)
}

func upInsertData(c *schema.Context) error {
	sqls := []string{
		`INSERT INTO users (id, username, email)
VALUES
    (1, 'john_doe', 'john@example.com'),
    (2, 'jane_smith', 'jane@example.com'),
    (3, 'alice_wonderland', 'alice@example.com')`,
		`INSERT INTO posts (id, title, content, author_id)
VALUES
    (1, 'Introduction to SQL', 'SQL is a powerful language for managing databases...', 1),
    (2, 'Data Modeling Techniques', 'Choosing the right data model is crucial...', 2),
    (3, 'Advanced Query Optimization', 'Optimizing queries can greatly improve...', 1)`,
		`INSERT INTO comments (id, post_id, user_id, content)
VALUES
    (1, 1, 3, 'Great introduction! Looking forward to more.'),
    (2, 1, 2, 'SQL can be a bit tricky at first, but practice helps.'),
    (3, 2, 1, 'You covered normalization really well in this post.')`,
	}
	for _, sql := range sqls {
		_, err := c.Exec(sql)
		if err != nil {
			return err
		}
	}
	return nil
}

func downInsertData(c *schema.Context) error {
	sqls := []string{
		"DELETE FROM comments",
		"DELETE FROM posts",
		"DELETE FROM users",
	}
	for _, sql := range sqls {
		_, err := c.Exec(sql)
		if err != nil {
			return err
		}
	}
	return nil
}
