-- =====================================================================
-- Compensation coupon (order page > "Generate compensation coupon")
--
-- No schema change: the coupon is an ordinary cart_base coupon; its link to
-- the order is kept in coupons.details ("compensation"), and it is limited to
-- the order's customer through coupon_allowed_users.
--
-- 1. Permission `generate_compensation_coupon` in its own Staff Roles section
--    "Compensation Coupons", granted to nobody: tick it for the customer
--    service role in Staff > Roles.
-- 2. Arabic UI strings.
--
-- Same rows as migration 2026_09_29_000001_add_compensation_coupon_permission.
-- Re-running the file changes nothing (only missing rows are inserted).
-- After running: php artisan cache:clear (permissions and translations are cached).
-- =====================================================================

SET NAMES utf8mb4;

INSERT INTO `permissions` (`name`, `section`, `guard_name`, `created_at`, `updated_at`)
SELECT 'generate_compensation_coupon', 'compensation_coupons', 'web', NOW(), NOW()
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `permissions` WHERE `name` = 'generate_compensation_coupon' AND `guard_name` = 'web'
);

INSERT INTO `translations` (`lang`, `lang_key`, `lang_value`, `created_at`, `updated_at`)
SELECT s.lang, s.lang_key, s.lang_value, NOW(), NOW()
FROM (
        SELECT 'en' AS lang, 'generate_compensation_coupon' AS lang_key, 'Generate Compensation Coupon' AS lang_value
        UNION ALL SELECT 'ar', 'generate_compensation_coupon', 'توليد كوبون تعويض لطلب'
        UNION ALL SELECT 'sa', 'generate_compensation_coupon', 'توليد كوبون تعويض لطلب'
        UNION ALL SELECT 'en', 'compensation_coupons', 'Compensation Coupons'
        UNION ALL SELECT 'ar', 'compensation_coupons', 'كوبونات التعويض'
        UNION ALL SELECT 'sa', 'compensation_coupons', 'كوبونات التعويض'
        UNION ALL SELECT 'en', 'compensation_coupon', 'Compensation coupon'
        UNION ALL SELECT 'ar', 'compensation_coupon', 'كوبون تعويض'
        UNION ALL SELECT 'sa', 'compensation_coupon', 'كوبون تعويض'
        UNION ALL SELECT 'en', 'compensation_coupon_created', 'Compensation coupon created'
        UNION ALL SELECT 'ar', 'compensation_coupon_created', 'تم توليد كوبون التعويض'
        UNION ALL SELECT 'sa', 'compensation_coupon_created', 'تم توليد كوبون التعويض'
        UNION ALL SELECT 'en', 'generate_compensation_coupon', 'Generate compensation coupon'
        UNION ALL SELECT 'ar', 'generate_compensation_coupon', 'توليد كوبون تعويض'
        UNION ALL SELECT 'sa', 'generate_compensation_coupon', 'توليد كوبون تعويض'
        UNION ALL SELECT 'en', 'onetime_coupon_for_the_customer_of_this_order_only', 'One-time coupon for the customer of this order only'
        UNION ALL SELECT 'ar', 'onetime_coupon_for_the_customer_of_this_order_only', 'كوبون لمرة واحدة لصاحب هذا الطلب فقط'
        UNION ALL SELECT 'sa', 'onetime_coupon_for_the_customer_of_this_order_only', 'كوبون لمرة واحدة لصاحب هذا الطلب فقط'
        UNION ALL SELECT 'en', 'valid_for', 'Valid for'
        UNION ALL SELECT 'ar', 'valid_for', 'صالح لمدة'
        UNION ALL SELECT 'sa', 'valid_for', 'صالح لمدة'
        UNION ALL SELECT 'en', 'days', 'days'
        UNION ALL SELECT 'ar', 'days', 'يوم'
        UNION ALL SELECT 'sa', 'days', 'يوم'
        UNION ALL SELECT 'en', 'reason_optional', 'Reason (optional)'
        UNION ALL SELECT 'ar', 'reason_optional', 'السبب (اختياري)'
        UNION ALL SELECT 'sa', 'reason_optional', 'السبب (اختياري)'
        UNION ALL SELECT 'en', 'valid_until', 'Valid until'
        UNION ALL SELECT 'ar', 'valid_until', 'صالح حتى'
        UNION ALL SELECT 'sa', 'valid_until', 'صالح حتى'
        UNION ALL SELECT 'en', 'issued_on_order', 'Issued on order'
        UNION ALL SELECT 'ar', 'issued_on_order', 'صدر على الطلب'
        UNION ALL SELECT 'sa', 'issued_on_order', 'صدر على الطلب'
        UNION ALL SELECT 'en', 'not_used_yet', 'Not used yet'
        UNION ALL SELECT 'ar', 'not_used_yet', 'لم يُستخدم بعد'
        UNION ALL SELECT 'sa', 'not_used_yet', 'لم يُستخدم بعد'
        UNION ALL SELECT 'en', 'used', 'Used'
        UNION ALL SELECT 'ar', 'used', 'مستخدم'
        UNION ALL SELECT 'sa', 'used', 'مستخدم'
        UNION ALL SELECT 'en', 'expired', 'Expired'
        UNION ALL SELECT 'ar', 'expired', 'منتهي'
        UNION ALL SELECT 'sa', 'expired', 'منتهي'
        UNION ALL SELECT 'en', 'inactive', 'Inactive'
        UNION ALL SELECT 'ar', 'inactive', 'غير مفعّل'
        UNION ALL SELECT 'sa', 'inactive', 'غير مفعّل'
        UNION ALL SELECT 'en', 'copied', 'Copied'
        UNION ALL SELECT 'ar', 'copied', 'تم النسخ'
        UNION ALL SELECT 'sa', 'copied', 'تم النسخ'
        UNION ALL SELECT 'en', 'this_order_has_no_registered_customer_so_it_cannot_get_a_compensation_coupon', 'This order has no registered customer, so it cannot get a compensation coupon.'
        UNION ALL SELECT 'ar', 'this_order_has_no_registered_customer_so_it_cannot_get_a_compensation_coupon', 'هذا الطلب ليس له زبون مسجّل، لذلك لا يمكن توليد كوبون تعويض له.'
        UNION ALL SELECT 'sa', 'this_order_has_no_registered_customer_so_it_cannot_get_a_compensation_coupon', 'هذا الطلب ليس له زبون مسجّل، لذلك لا يمكن توليد كوبون تعويض له.'
        UNION ALL SELECT 'en', 'a_compensation_coupon_was_already_issued_for_this_order', 'A compensation coupon was already issued for this order.'
        UNION ALL SELECT 'ar', 'a_compensation_coupon_was_already_issued_for_this_order', 'تم توليد كوبون تعويض لهذا الطلب مسبقاً.'
        UNION ALL SELECT 'sa', 'a_compensation_coupon_was_already_issued_for_this_order', 'تم توليد كوبون تعويض لهذا الطلب مسبقاً.'
        UNION ALL SELECT 'en', 'the_syp_exchange_rate_is_not_set_so_the_coupon_value_cannot_be_calculated', 'The SYP exchange rate is not set, so the coupon value cannot be calculated.'
        UNION ALL SELECT 'ar', 'the_syp_exchange_rate_is_not_set_so_the_coupon_value_cannot_be_calculated', 'سعر صرف الليرة غير مضبوط، لا يمكن حساب قيمة الكوبون.'
        UNION ALL SELECT 'sa', 'the_syp_exchange_rate_is_not_set_so_the_coupon_value_cannot_be_calculated', 'سعر صرف الليرة غير مضبوط، لا يمكن حساب قيمة الكوبون.'
        UNION ALL SELECT 'en', 'coupons_cannot_be_limited_to_one_customer_yet_coupon_allowed_users_is_missing', 'Coupons cannot be limited to one customer yet (coupon_allowed_users is missing).'
        UNION ALL SELECT 'ar', 'coupons_cannot_be_limited_to_one_customer_yet_coupon_allowed_users_is_missing', 'لا يمكن حصر الكوبون بزبون واحد بعد (جدول coupon_allowed_users غير موجود).'
        UNION ALL SELECT 'sa', 'coupons_cannot_be_limited_to_one_customer_yet_coupon_allowed_users_is_missing', 'لا يمكن حصر الكوبون بزبون واحد بعد (جدول coupon_allowed_users غير موجود).'
) AS s
WHERE NOT EXISTS (
    SELECT 1 FROM `translations` t
    WHERE t.lang = s.lang AND t.lang_key = s.lang_key
);
