-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             12.6.0.6765
-- --------------------------------------------------------



-- Dumping database structure for caurlaidesapp
CREATE DATABASE IF NOT EXISTS `caurlaidesapp` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
USE `caurlaidesapp`;

-- Dumping structure for table caurlaidesapp.companies
CREATE TABLE IF NOT EXISTS `companies` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `address` text NOT NULL,
  `created_at` date DEFAULT NULL,
  `updated_at` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Dumping data for table caurlaidesapp.companies: ~2 rows (approximately)
INSERT INTO `companies` (`id`, `name`, `address`, `created_at`, `updated_at`) VALUES
	(6, 'QQQ', 'gdfgfdgh', '2024-12-02', '2024-12-09'),
	(9, 'DDD', 'v ananas', '2024-12-13', '2024-12-13');

-- Dumping structure for function caurlaidesapp.delete_funkc
DELIMITER //
CREATE FUNCTION `delete_funkc`(`id` INT,
	`pass_id` INT
) RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
BEGIN
    DECLARE result_message VARCHAR(255);

    -- Check if the row was actually deleted
    IF ROW_COUNT() > 0 THEN
        SET result_message = CONCAT('Pass with ID ', pass_id, ' has been successfully deleted.');
    ELSE
        SET result_message = CONCAT('Pass with ID ', pass_id, ' does not exist.');
    END IF;

    RETURN result_message;
END//
DELIMITER ;

-- Dumping structure for function caurlaidesapp.remaining_funkc
DELIMITER //
CREATE FUNCTION `remaining_funkc`(`id` INT,
	`pass_id` INT
) RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
    DETERMINISTIC
BEGIN
    DECLARE remaining_visits INT;
    DECLARE result_message VARCHAR(255);

    -- Handle scenarios based on the remaining visits
    IF remaining_visits IS NULL THEN
        SET result_message = CONCAT('Pass with ID ', pass_id, ' not found.');
        SET result_message = CONCAT('Pass with ID ', pass_id, ' decremented. Remaining visits: ', remaining_visits - 1);
    ELSE
        SET result_message = CONCAT('Pass with ID ', pass_id, ' has no remaining visits.');
    END IF;

    RETURN result_message;
END//
DELIMITER ;

