INSERT INTO ohrm_data_group (name, description, can_read, can_create, can_update, can_delete)
VALUES ('recruitment_preboarding_candidate_welcome', 'Recruitment (ATS) - Onboarding - Candidate Welcome', 1, 0, 1, 0);

SET @data_group_id := (SELECT `id`
                       FROM `ohrm_data_group`
                       WHERE `name` = 'recruitment_preboarding_candidate_welcome');
SET @candidate_role_id := (SELECT `id`
                            FROM `ohrm_user_role`
                            WHERE `name` = 'CandidateUser');

INSERT INTO ohrm_user_role_data_group (user_role_id, data_group_id, can_read, can_create, can_update, can_delete, self,
                                       restriction_id)
VALUES (@candidate_role_id, @data_group_id, 1, 0, 1, 0, 0, NULL);

SET @system_user_id := (SELECT `id`
                        FROM `ohrm_user`
                        WHERE `user_name` = 'System');


INSERT INTO ohrm_dynamic_form (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                               updated_by, created_by_name, version)
VALUES ('Welcome Candidate', 'Welcome Candidate', 'POST',
        'recruitment_preboarding_candidate_welcome', null, @data_group_id, @system_user_id, @system_user_id, 'System', 1);

SET @dynamic_form_id := (SELECT `id`
                         FROM ohrm_dynamic_form
                         WHERE name = 'Welcome Candidate');

INSERT INTO ohrm_dynamic_form_version (`name`, description, `action`, endpoint, meta_data, data_group_id, created_by,
                                       updated_by, created_by_name, version, dynamic_form_id)
VALUES ('Welcome Candidate', 'Welcome Candidate', 'POST', 'recruitment_preboarding_candidate_welcome',
        null, @data_group_id, @system_user_id, @system_user_id, 'System', 1, @dynamic_form_id);

SET @dynamic_form_version_id := (SELECT `id`
                                 FROM ohrm_dynamic_form_version
                                 WHERE name = 'Welcome Candidate');

SET @metadata = '
{
    "version": {
        "schema-version": "1.0.0"
    },
    "fields": [],
    "views": {
        "form": {
            "uid": "form004",
            "action": "POST",
            "endpoint": "forms/4",
            "body": [
                {
                    "uid": "form004_container",
                    "tag": "div",
                    "props": {
                        "style": "overflow: hidden; text-align:center; margin-left: 10%; margin-right: 10%; height: 50vh;"
                    },
                    "slots": {
                        "default": [
                            {
                                "uid": "form004_iframe",
                                "tag": "iframe",
                                "props": {
                                    "frameborder": "0",
                                    "title": "YouTube video player",
                                    "style": "width: 100%; height: 100%;",
                                    "src": "https://in-app-marketing.orangehrm.com/",
                                    "allow": "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
                                }
                            }
                        ]
                    }
                },
                {
                    "uid": "form004_iframe",
                    "tag": "div",
                    "props": {
                        "style": "text-align:center;"
                    },
                    "slots": {
                        "default": [
                            {
                                "uid": "form004_title",
                                "tag": "oxd-text",
                                "props": {
                                    "type": "card-title",
                                    "style": "margin-bottom: 20px; margin-top: 50px;"
                                },
                                "slots": {
                                    "default": [
                                        "Welcome to the Colten Care Candidate Questionnaire"
                                    ]
                                }
                            },
                            {
                                "uid": "form004_title",
                                "tag": "oxd-text",
                                "props": {
                                    "type": "p",
                                    "style": "margin-bottom: 20px; margin-top: 20px;"
                                },
                                "slots": {
                                    "default": [
                                        "Two Referee | BDS Details | Past Employment | Details Health Questionnaire | Bank Details | Payroll Details"
                                    ]
                                }
                            },
                            {
                                "uid": "form003_title",
                                "tag": "oxd-text",
                                "props": {
                                    "type": "p",
                                    "style": "margin-bottom: 20px; margin-top: 20px;"
                                },
                                "slots": {
                                    "default": [
                                        "Once you fill all these and complete, the processing at Colten Care wll take place. Note that the Colten Care will reach the referees to collect reference from them"
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "uid": "form004_br",
                    "tag": "br"
                },
                {
                    "uid": "form004_buttons",
                    "tag": "div",
                    "props": {
                        "style": "display: flex; justify-content: space-between; margin-top: 1rem; float: right;"
                    },
                    "slots": {
                        "default": [
                            {
                                "uid": "form004_button_submit",
                                "tag": "oxd-button",
                                "props": {
                                    "type": "button",
                                    "label": "Proceed"
                                },
                                "events": {
                                    "onClick": "#onClickSubmitButton"
                                }
                            }
                        ]
                    }
                }
            ],
            "model": {},
            "computed": {},
            "methods": {
                "onClickSubmitButton": {
                    "#validate": {},
                    "#save": {
                        "action": "Submit"
                    }
                }
            }
        }
    }
}';

UPDATE ohrm_dynamic_form
SET meta_data = @metadata
WHERE id = @dynamic_form_id;

UPDATE ohrm_dynamic_form_version
SET meta_data = @metadata
WHERE id = @dynamic_form_version_id;
