DROP PROCEDURE IF EXISTS mocha_set_parent_class;

CREATE PROCEDURE mocha_set_parent_class
(
    IN p_source_inst_id INT,
    IN p_class_inst_id INT,
    IN p_user_inst_id INT,
    IN p_effective_date DATETIME
)
BEGIN
    DECLARE z_effective_date DATETIME;

    IF p_effective_date IS NULL THEN
        SET z_effective_date = NOW();
    ELSE
        SET z_effective_date = p_effective_date;
    END IF;

    CALL mocha_assign_relationship
    (
        p_source_inst_id,
        mocha_get_instance_by_global_identifier('494D5A6D04BE477B8763E3F57D0DD8C8'),
        p_class_inst_id,
        p_user_inst_id,
        z_effective_date
    );

    CALL mocha_assign_relationship
    (
        p_class_inst_id,
        mocha_get_instance_by_global_identifier('7EB41D3C2AE9488483A4E59441BCAEFB'),
        p_source_inst_id,
        p_user_inst_id,
        z_effective_date
    );

END;
