/**
 * 存储类型定义
 */

// 订阅源
export class Subscription {
  constructor(data = {}) {
    this.id = data.id || crypto.randomUUID();
    this.name = data.name || '';
    this.url = data.url || '';
    this.type = data.type || 'm3u'; // 'm3u' | 'txt'
    this.enabled = data.enabled !== false;
    this.lastUpdated = data.lastUpdated || 0;
    this.etag = data.etag || '';
  }
}

// 频道
export class Channel {
  constructor(data = {}) {
    this.id = data.id || '';
    this.name = data.name || '';
    this.group = data.group || '';
    this.urls = data.urls || []; // string[]
    this.logo = data.logo || '';
    this.epgId = data.epgId || '';
  }
}

// 线路有效性
export class SourceValidity {
  constructor(data = {}) {
    this.url = data.url || '';
    this.status = data.status || 'unknown'; // 'online' | 'offline' | 'unknown'
    this.checkedAt = data.checkedAt || 0;
    this.latency = data.latency || 0;
    this.failCount = data.failCount || 0;
  }
}

// 用户偏好
export class Preferences {
  constructor(data = {}) {
    this.defaultGroup = data.defaultGroup || '';
    this.autoPlay = data.autoPlay !== false;
    this.preferredQuality = data.preferredQuality || 'auto'; // 'auto' | 'hd' | 'sd'
    this.volume = data.volume ?? 1.0;
    this.listCacheTTL = data.listCacheTTL || 24 * 60 * 60 * 1000; // 1天
    this.validityCacheTTL = data.validityCacheTTL || 12 * 60 * 60 * 1000; // 12小时
  }
}

// 播放历史
export class PlayHistory {
  constructor(data = {}) {
    this.channelId = data.channelId || '';
    this.channelName = data.channelName || '';
    this.sourceUrl = data.sourceUrl || '';
    this.timestamp = data.timestamp || Date.now();
    this.duration = data.duration || 0;
  }
}

// 缓存元数据
export class CacheMeta {
  constructor(data = {}) {
    this.key = data.key || '';
    this.updatedAt = data.updatedAt || 0;
    this.size = data.size || 0;
    this.version = data.version || 1;
  }
}
