export type EmergencyContact={name:string;phone:string};
export function validContacts(value:any,complete=false):value is EmergencyContact[]{return Array.isArray(value)&&value.length===3&&value.every(c=>c&&typeof c.name==='string'&&c.name.length<=80&&typeof c.phone==='string'&&c.phone.length<=30&&(!complete||c.name.trim()&&/^\+[1-9]\d{7,14}$/.test(c.phone)))&&(!complete||new Set(value.map(c=>c.phone)).size===3)}
export function validLocation(v:any){return v===null||v&&Number.isFinite(v.lat)&&Math.abs(v.lat)<=90&&Number.isFinite(v.lng)&&Math.abs(v.lng)<=180&&Number.isFinite(v.accuracy)&&v.accuracy>=0&&Number.isFinite(v.time)&&Math.abs(Date.now()-v.time)<120000}
export function helpMessage(name:string,location:any){return `SOVEREIGN HELP ALERT: ${name||'Your nominated contact'} needs help. Please contact them now. ${location?`Location: https://maps.google.com/?q=${location.lat},${location.lng} (accuracy approximately ${Math.round(location.accuracy)}m; captured ${new Date(location.time).toISOString()}).`:'Location unavailable. Ask where they are.'} Alert prepared ${new Date().toISOString()}. This is a request for help, not an emergency-service dispatch.`}
export function smsLink(phone:string,message:string){return `sms:${phone}?body=${encodeURIComponent(message)}`}
