CREATE TABLE action.forms (
    form_id INT(11) AUTO_INCREMENT PRIMARY KEY,
    form_uuid VARCHAR(200) NOT NULL,
    account_id INT(11) NOT NULL,
    form_name VARCHAR(255) NOT NULL,
    created_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    published_date DATETIME DEFAULT NULL,
    is_deleted TINYINT(1) DEFAULT 0,
    is_global TINYINT(1) DEFAULT 0,
    is_shared TINYINT(1) DEFAULT 0,
)

ALTER TABLE action.forms
    DROP COLUMN is_global,
    DROP COLUMN is_shared,
    ADD COLUMN is_default TINYINT(1) DEFAULT 0,
    ADD COLUMN is_template TINYINT(1) DEFAULT 0;

CREATE TABLE action.forms_default (
    form_id INT(11) NOT NULL,
    account_id INT(11) NOT NULL,
    CONSTRAINT default_form_to_form FOREIGN KEY (form_id) REFERENCES action.forms(form_id)
        ON DELETE CASCADE,
    CONSTRAINT default_form_to_account UNIQUE (account_id)
)

DROP TABLE action.forms_default;

INSERT INTO action.translations_core
(tx_core_loc_key, tx_core_language_code, tx_core_translation)
VALUES
('form_builder_tab_title', 'en', 'Form Builder'),
('form_builder_page_title', 'en', 'Form List'),
('form_builder_add_form', 'en', 'Create New Form'),
('form_builder_no_forms', 'en', 'No forms found.'),
('form_builder_assign_teams', 'en', 'Assign %teams%'),
('form_builder_name_col', 'en', 'Name'),
('form_builder_created_col', 'en', 'Created'),
('form_builder_published_col', 'en', 'Published'),
('form_builder_team_col', 'en', 'Assigned %teams%'),
('form_builder_option_view', 'en', 'View'),
('form_builder_option_edit', 'en', 'Edit'),
('form_builder_option_settings', 'en', 'Manage Settings'),
('form_builder_option_duplicate', 'en', 'Duplicate'),
('form_builder_option_delete', 'en', 'Delete'),
('form_builder_option_delete_msg', 'en', 'Are you sure you want to delete this form? Any assigned %teams% will immediately begin using the default form.'),
('form_builder_add_panel_title', 'en', 'Create New Form'),
('form_builder_settings_panel_title', 'en', 'Form Settings'),
('form_builder_default', 'en', 'default'),
('form_builder_no_default_msg', 'en', 'No default form is set for this account. Only %teams% with explicit form assignment will be able to complete %checkins%.'),
('form_builder_settings_panel_created_lbl', 'en', 'Created'),
('form_builder_settings_panel_published_lbl', 'en', 'Last Published'),
('form_builder_settings_panel_unpublished_lbl', 'en', '%n% Unpublished Changes'),
('form_builder_settings_panel_account_access', 'en', 'Account Access'),
('form_builder_settings_panel_account_access_shared', 'en', 'Share with Sub Accounts'),
('form_builder_settings_panel_account_access_global', 'en', 'Is Global'),
('form_builder_settings_panel_form_name', 'en', 'Form Name'),
('form_builder_form_add_successful', 'en', 'Form Added!'),
('form_builder_settings_panel_options', 'en', 'Options'),
('form_builder_settings_panel_default_form', 'en', 'Make this the default form'),
('form_builder_settings_panel_assigned_teams_lbl', 'en', 'Assigned %teams%'),
('form_builder_settings_panel_assigned_teams_count', 'en', 'Count: %n%'),
('form_builder_settings_panel_assigned_teams_none_assigned', 'en', 'No Assignments'),
('form_builder_delete_form_success', 'en', 'Form Deleted!'),
('form_builder_duplicate_form_success', 'en', 'Form Duplicated!'),
('form_assignment_modal_title', 'en', 'Assign %teams% to Forms'),
('form_assignment_modal_descrip_1', 'en', 'Make assignments regarding which %checkin% form each %team% in the hierarchy should use.'),
('form_assignment_modal_descrip_2', 'en', 'Please note: changing form assignments for %teams% could result in fragmented time-series data.'),
('form_assignment_modal_default_form', 'en', 'Default Form'),
('form_assignment_modal_edit_assignment', 'en', 'Edit'),
('form_assignment_modal_copy_assignment', 'en', 'Copy assignment downstream'),
('form_assignment_modal_remove_assignment', 'en', 'Remove'),
('form_assignment_modal_assignment_processing', 'en', 'Updates in progress. Please do not close the window.')
;

INSERT INTO action.translations_terminology (language_code, translation_code, translation)
VALUES ('en', 'teams', 'teams');
