import os
import sys

import pytest

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from services.notifications.sms_service import SMSService


@pytest.fixture(autouse=True)
def set_env_vars():
    os.environ['SUPPRESS_SMS'] = 'true'

# Test for type_of_content method
def test_type_of_content():
    assert SMSService.type_of_content("instagramStory") == "Instagram Story"
    assert SMSService.type_of_content("instagramPost") == "Instagram Post"
    assert SMSService.type_of_content("instagramReel") == "Instagram Reel"
    assert SMSService.type_of_content("ugc") == "photo"
    assert SMSService.type_of_content("ugcPicture") == "photo"
    assert SMSService.type_of_content("ugcPicture") == "video"


# Test for credit description with a single amount (cash)
def test_generate_reward_description_single_cash_off():
    description = SMSService.generate_reward_description("cash", "100")
    assert description == "$100 off"

# Test for credit description with a single amount (percentage)
def test_generate_reward_description_single_percent_off():
    description = SMSService.generate_reward_description("percent", "10")
    assert description == "10% off"

# Test for cash credit description with a range
def test_generate_reward_description_range_cash_off():
    description = SMSService.generate_reward_description("cash", None, 50, 150)
    assert description == "up to $150 off"

# Test for percentage credit description with a range
def test_generate_reward_description_range_percent_off():
    description = SMSService.generate_reward_description("percent", None, 5, 15)
    assert description == "up to 15% off"

# Test for cash credit description with a range and a single amount (should return the range)
def test_generate_reward_description_range_cash_off():
    description = SMSService.generate_reward_description("cash", 100, 50, 150)
    assert description == "up to $150 off"

def test_generate_reward_description_range_hard_cash():
    description = SMSService.generate_reward_description("cash", None, 5, 15, hard_cash=True)
    assert description == "up to $15"

# Test cash offer credit reminder text
def test_credit_reminder_text_cash():
    text, response = SMSService.send_credit_reminder_text("+11234567899", "Strapt", compensation=100, credit_type="cash")
    assert "$100 off" in text

# Test percent offer credit reminder text
def test_credit_reminder_text_percent():
    text, response = SMSService.send_credit_reminder_text("+11234567899", "Strapt", compensation=10, credit_type="percent")
    assert "10% off" in text

def test_credit_reminder_text_whitelabeled():
    text, response = SMSService.send_credit_reminder_text("+11234567899", "Strapt", compensation=10, credit_type="percent", whitelabel_url="offers.gymshark.com")
    assert "10% off" in text
    assert "https://offers.gymshark.com" in text

# Test post reminder text w/ cash
def test_post_reminder_text_cash():
    text, response = SMSService.send_post_reminder_text("+11234567899", "straptofficial", content_type="instagramPost" , compensation=20, credit_type="cash")
    assert "$20 off" in text

# Test post reminder text w/ percent
def test_story_reminder_text_percent():
    text, response = SMSService.send_post_reminder_text("+11234567899", "straptofficial", content_type="instagramStory", compensation=5, credit_type="percent")
    assert "5% off" in text

# Test post reminder text w/ range
def test_post_reminder_text_range():
    text, response = SMSService.send_post_reminder_text("+11234567899", "straptofficial", content_type="ugc", compensation=5, credit_type="percent", min_compensation=1, max_compensation=10)
    assert "up to 10% off" in text

# Test private offer text (cash, single amount)
def test_private_offer_text_single_cash():
    text, response = SMSService.send_private_offer_alert_text("+11234567899", "Strapt", client_ig_handle="straptofficial", content_type="instagramPost", credit_type="cash", compensation=100)
    assert "$100 off" in text
    assert "/wallet" in text

# Test private offer text (percent, single amount)
def test_private_offer_text_single_percent():
    text, response = SMSService.send_private_offer_alert_text("+11234567899", "Strapt", client_ig_handle="straptofficial", content_type="instagramStory", credit_type="percent", compensation=10)
    assert "10% off" in text
    assert "/wallet" in text

# Test private offer text (cash, range)
def test_private_offer_text_range_cash():
    text, response = SMSService.send_private_offer_alert_text("+11234567899", "Strapt", client_ig_handle="straptofficial", content_type="instagramPost", credit_type="cash", min_compensation=50, max_compensation=150)
    assert "up to $150 off" in text
    assert "/wallet" in text

# Test private offer text (percent, range)
def test_private_offer_text_range_percent():
    text, response = SMSService.send_private_offer_alert_text("+11234567899", "Strapt", client_ig_handle="straptofficial", content_type="instagramStory", credit_type="percent", min_compensation=5, max_compensation=15)
    assert "up to 15% off" in text
    assert "/wallet" in text

# Test private offer text (hard cash, range, whitelabeled)
def test_private_offer_text_range_hard_cash_whitelabeled():
    text, response = SMSService.send_private_offer_alert_text("+11234567899", "Strapt", client_ig_handle="straptofficial", content_type="instagramPost", credit_type="cash", min_compensation=50, max_compensation=150, whitelabel_url="offers.strapt.us", hard_cash=True)
    assert "up to $150" in text
    assert "off" in text
    assert "/wallet" in text

# test offer acceptance text
def test_offer_acceptance_text():
    text, response = SMSService.send_offer_acceptance_text("+11234567899", "Jason", "Strapt", "instagramPost")
    assert "Jason" in text
    assert "Strapt" in text
    assert "Instagram Post" in text
    


