package model

import (
	"context"
	"fmt"
	"time"
)

type ProxyInfo struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Protocol string `json:"protocol"` // http, https, socks5
}

func (p *ProxyInfo) String() string {
	if p.Username != "" && p.Password != "" {
		return fmt.Sprintf("%s://%s:%s@%s:%d", p.Protocol, p.Username, p.Password, p.Host, p.Port)
	}
	return fmt.Sprintf("%s://%s:%d", p.Protocol, p.Host, p.Port)
}

type IProxyPoolStrategy interface {
	GetProxy(ctx context.Context, orderId string) (*ProxyInfo, error)

	SetProxy(ctx context.Context, orderId string, proxy *ProxyInfo) error

	RemoveProxy(ctx context.Context, orderId string) error

	GetTTL(ctx context.Context, orderId string) (time.Duration, error)
}
