namespace GBDD
{
    public class UserFines : Form
    {
        private int driverId;
        private DataGridView dataGridView1;
        private Button button1;

        public UserFines(int id)
        {
            driverId = id;

            Text = "Мои штрафы";
            Width = 800;
            Height = 450;

            button1 = new Button();
            button1.Text = "Обновить";
            button1.Location = new Point(20, 20);
            button1.Size = new Size(120, 35);
            button1.Click += button1_Click;

            dataGridView1 = new DataGridView();
            dataGridView1.Location = new Point(20, 70);
            dataGridView1.Size = new Size(740, 320);
            dataGridView1.ReadOnly = true;
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            Controls.Add(button1);
            Controls.Add(dataGridView1);

            Load += UserFines_Load;
        }

        private void UserFines_Load(object? sender, EventArgs e)
        {
            LoadFines();
        }

        private void button1_Click(object? sender, EventArgs e)
        {
            LoadFines();
        }

        private void LoadFines()
        {
            dataGridView1.DataSource = Db.Select($"""
                select id, uin, violation_type, occurred_at, amount, status, paid_at
                from user_fine_view
                where driver_id = {driverId}
                order by id desc
                """);
        }
    }
}
