-- create new lesson package types

ALTER TABLE lesson_package_types ADD COLUMN is_test_drive BOOLEAN NOT NULL DEFAULT TRUE;
UPDATE lesson_package_types SET is_test_drive = FALSE WHERE id in('single', 'single-free');

INSERT INTO lesson_package_types (id, name, description, package_type, price, is_test_drive) VALUES ('amazon-test-drive-free-4', 'Test Drive (4)', 'Four free lessons which you can use to find that ideal teacher.', 'test-drive-4', 0.0, TRUE);
INSERT INTO lesson_package_types (id, name, description, package_type, price, is_test_drive) VALUES ('amazon-test-drive-free-2', 'Test Drive (2)', 'Two free lessons which you can use to find that ideal teacher.', 'test-drive-2', 0.0, TRUE);
INSERT INTO lesson_package_types (id, name, description, package_type, price, is_test_drive) VALUES ('amazon-test-drive-paid-4', 'Test Drive (4)', 'Four reduced-price lessons which you can use to find that ideal teacher.', 'test-drive-4', 19.99, TRUE);


-- need new posa card types for Amazon -- should be able to point to lesson package type
ALTER TABLE posa_cards ADD COLUMN lesson_package_type_id VARCHAR(64) REFERENCES lesson_package_types(id) ON DELETE SET NULL;
ALTER TABLE posa_cards ADD COLUMN credits INTEGER NOT NULL DEFAULT 1;
ALTER TABLE posa_cards ADD COLUMN is_lesson BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE posa_cards ADD COLUMN preactivate BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE posa_cards ADD COLUMN requires_purchase BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE posa_cards ADD COLUMN purchased BOOLEAN NOT NULL DEFAULT TRUE;

ALTER TABLE lesson_bookings ADD COLUMN posa_card_purchased BOOLEAN NOT NULL DEFAULT FALSE;

update posa_cards set credits = 5 where card_type = 'jam_tracks_5';
update posa_cards set credits = 10 where card_type = 'jam_tracks_10';
update posa_cards set credits = 4 where card_type = 'jam_class_4';
update posa_cards set is_lesson = TRUE where card_type = 'jam_class_4';
update posa_cards set lesson_package_type_id = 'test-drive' where card_type = 'jam_class_4';

ALTER TABLE lesson_package_purchases ADD COLUMN total_roll_forward_amount_in_cents INTEGER;
ALTER TABLE lesson_package_purchases ADD COLUMN remaining_roll_forward_amount_in_cents INTEGER;
ALTER TABLE lesson_package_purchases ADD COLUMN reduced_roll_forward_amount_in_cents INTEGER NOT NULL DEFAULT 0;

ALTER TABLE lesson_package_purchases ADD COLUMN expected_session_times INTEGER;
ALTER TABLE lesson_package_purchases ADD COLUMN actual_session_times INTEGER;
ALTER TABLE teacher_distributions    ADD COLUMN reduced_roll_forward_amount_in_cents INTEGER NOT NULL DEFAULT 0;

ALTER TABLE lesson_bookings ADD COLUMN remaining_roll_forward_amount_in_cents INTEGER NOT NULL DEFAULT 0;

ALTER TABLE users ADD COLUMN lesson_package_needs_purchase_id VARCHAR(64) REFERENCES lesson_package_types(id) ON DELETE SET NULL;

ALTER TABLE lesson_sessions ADD COLUMN sent_counter_reminder BOOLEAN NOT NULL DEFAULT FALSE;

ALTER TABLE lesson_bookings ADD COLUMN student_canceled BOOLEAN DEFAULT FALSE NOT NULL;
ALTER TABLE lesson_bookings ADD COLUMN teacher_canceled BOOLEAN DEFAULT FALSE NOT NULL;
ALTER TABLE lesson_bookings ADD COLUMN student_canceled_at TIMESTAMP;
ALTER TABLE lesson_bookings ADD COLUMN teacher_canceled_at TIMESTAMP;
ALTER TABLE lesson_bookings ADD COLUMN teacher_canceled_reason VARCHAR;
ALTER TABLE lesson_bookings ADD COLUMN student_canceled_reason VARCHAR;
