package com.vpnpanel.api;

import com.vpnpanel.models.*;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.http.*;

public interface ApiService {
    
    // ==================== Authentication ====================
    
    @POST("auth/login.php")
    Call<LoginResponse> login(@Body LoginRequest request);
    
    @POST("auth/register.php")
    Call<RegisterResponse> register(@Body RegisterRequest request);
    
    // ==================== App Dashboard ====================
    
    @GET("app/dashboard.php")
    Call<DashboardResponse> getDashboard();
    
    // ==================== Servers ====================
    
    @GET("servers/list.php")
    Call<ServerListResponse> getServers(
        @Query("status") String status,
        @Query("location") String location
    );
    
    @GET("servers/configs.php")
    Call<ConfigListResponse> getServerConfigs(@Query("server_id") int serverId);
    
    // ==================== VPN Connection ====================
    
    @POST("app/connect.php")
    Call<ConnectResponse> connect(@Body ConnectRequest request);
    
    @POST("app/disconnect.php")
    Call<DisconnectResponse> disconnect(@Body DisconnectRequest request);
    
    // ==================== Subscriptions ====================
    
    @GET("subscriptions/my-subscriptions.php")
    Call<SubscriptionListResponse> getMySubscriptions();
    
    @GET("plans/list.php")
    Call<PlanListResponse> getPlans();
    
    @POST("payment/zarinpal.php")
    Call<PaymentResponse> createPayment(@Body PaymentRequest request);
    
    @POST("payment/callback.php")
    Call<PaymentVerifyResponse> verifyPayment(@Body PaymentVerifyRequest request);
    
    // ==================== Profile ====================
    
    @GET("users/profile.php")
    Call<ProfileResponse> getProfile();
    
    @PUT("users/profile.php")
    Call<ProfileResponse> updateProfile(@Body UpdateProfileRequest request);
    
    // ==================== Tickets ====================
    
    @GET("tickets/list.php")
    Call<TicketListResponse> getTickets(
        @Query("status") String status,
        @Query("page") int page
    );
    
    @POST("tickets/create.php")
    Call<TicketResponse> createTicket(@Body CreateTicketRequest request);
    
    @GET("tickets/messages.php")
    Call<TicketMessagesResponse> getTicketMessages(@Query("ticket_id") int ticketId);
    
    @POST("tickets/reply.php")
    Call<TicketMessageResponse> replyToTicket(@Body ReplyTicketRequest request);
    
    // ==================== Referrals ====================
    
    @GET("referrals/my-referrals.php")
    Call<ReferralResponse> getMyReferrals();
    
    @GET("referrals/stats.php")
    Call<ReferralStatsResponse> getReferralStats();
    
    // ==================== Notifications ====================
    
    @GET("notifications/list.php")
    Call<NotificationListResponse> getNotifications(@Query("unread_only") boolean unreadOnly);
    
    @PUT("notifications/mark-read.php")
    Call<ApiResponse> markNotificationAsRead(@Body Map<String, Integer> body);
}

// ==================== Request Models ====================

class LoginRequest {
    public String username;
    public String password;
    
    public LoginRequest(String username, String password) {
        this.username = username;
        this.password = password;
    }
}

class RegisterRequest {
    public String username;
    public String email;
    public String password;
    public String full_name;
    public String referral_code;
    
    public RegisterRequest(String username, String email, String password, String fullName, String referralCode) {
        this.username = username;
        this.email = email;
        this.password = password;
        this.full_name = fullName;
        this.referral_code = referralCode;
    }
}

class ConnectRequest {
    public int server_id;
    public Integer config_id;
    
    public ConnectRequest(int serverId, Integer configId) {
        this.server_id = serverId;
        this.config_id = configId;
    }
}

class DisconnectRequest {
    public int server_id;
    public Integer connection_id;
    
    public DisconnectRequest(int serverId, Integer connectionId) {
        this.server_id = serverId;
        this.connection_id = connectionId;
    }
}

class PaymentRequest {
    public int plan_id;
    public String payment_method;
    public String callback_url;
    
    public PaymentRequest(int planId, String paymentMethod, String callbackUrl) {
        this.plan_id = planId;
        this.payment_method = paymentMethod;
        this.callback_url = callbackUrl;
    }
}

class PaymentVerifyRequest {
    public String authority;
    public String status;
    
    public PaymentVerifyRequest(String authority, String status) {
        this.authority = authority;
        this.status = status;
    }
}

class UpdateProfileRequest {
    public String full_name;
    public String email;
    public String phone;
    
    public UpdateProfileRequest(String fullName, String email, String phone) {
        this.full_name = fullName;
        this.email = email;
        this.phone = phone;
    }
}

class CreateTicketRequest {
    public String subject;
    public String message;
    public String category;
    public String priority;
    
    public CreateTicketRequest(String subject, String message, String category, String priority) {
        this.subject = subject;
        this.message = message;
        this.category = category;
        this.priority = priority;
    }
}

class ReplyTicketRequest {
    public int ticket_id;
    public String message;
    
    public ReplyTicketRequest(int ticketId, String message) {
        this.ticket_id = ticketId;
        this.message = message;
    }
}

// ==================== Response Models ====================

class LoginResponse extends ApiResponse {
    public String token;
    public User user;
}

class RegisterResponse extends ApiResponse {
    public String token;
    public User user;
}

class DashboardResponse extends ApiResponse {
    public User user;
    public Subscription subscription;
    public List<ServerWithConfigs> servers;
    public UsageStats stats;
    public List<Plan> plans;
    public List<Ticket> tickets;
}

class ServerListResponse extends ApiResponse {
    public List<Server> servers;
    public Pagination pagination;
}

class ConfigListResponse extends ApiResponse {
    public List<VPNConfig> configs;
}

class ConnectResponse extends ApiResponse {
    public String config;
    public String protocol;
    public ServerInfo server_info;
}

class DisconnectResponse extends ApiResponse {
    public int duration_seconds;
}

class SubscriptionListResponse extends ApiResponse {
    public List<Subscription> subscriptions;
}

class PlanListResponse extends ApiResponse {
    public List<Plan> plans;
}

class PaymentResponse extends ApiResponse {
    public String payment_url;
    public String authority;
}

class PaymentVerifyResponse extends ApiResponse {
    public boolean verified;
    public Subscription subscription;
}

class ProfileResponse extends ApiResponse {
    public User user;
}

class TicketListResponse extends ApiResponse {
    public List<Ticket> tickets;
    public Pagination pagination;
}

class TicketResponse extends ApiResponse {
    public Ticket ticket;
}

class TicketMessagesResponse extends ApiResponse {
    public List<TicketMessage> messages;
}

class TicketMessageResponse extends ApiResponse {
    public TicketMessage message;
}

class ReferralResponse extends ApiResponse {
    public String referral_code;
    public List<Referral> referrals;
}

class ReferralStatsResponse extends ApiResponse {
    public int total_referrals;
    public int active_referrals;
    public long total_commission;
}

class NotificationListResponse extends ApiResponse {
    public List<Notification> notifications;
    public int unread_count;
}

class ApiResponse {
    public boolean success;
    public String message;
    public int code;
}

class Pagination {
    public int total;
    public int page;
    public int limit;
    public int pages;
}

class ServerWithConfigs extends Server {
    public List<VPNConfig> configs;
}

class ServerInfo {
    public int id;
    public String name;
    public String location;
    public String ip;
    public int port;
}

class UsageStats {
    public long total_traffic;
    public int connection_days;
    public String last_connection;
}

class VPNConfig {
    public int id;
    public String protocol;
    public String config;
    public Integer port;
    public String encryption;
    public String remarks;
}

class Referral {
    public int id;
    public String username;
    public String created_at;
    public String status;
}

class Notification {
    public int id;
    public String title;
    public String message;
    public String type;
    public boolean is_read;
    public String created_at;
}

class TicketMessage {
    public int id;
    public String message;
    public String author_role;
    public String created_at;
}
